package com.hippo.provider.controller.task;

import com.hippo.core.pojo.vo.result.BaseResult;
import com.hippo.provider.task.TaskSchedulerTest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName TaskTestController
 * @Description TODO 定时任务测试接口
 * @Author tangxl
 * @create 2023-04-28 11:35
 **/
@RestController
@Tag(name = "定时任务测试接口")
@RequestMapping("/task")
@RequiredArgsConstructor
public class TaskTestController {
    private final TaskSchedulerTest taskSchedulerTest;
    @GetMapping("/start")
    @Operation(summary = "根据任务编码开始定时任务")
    @Parameters({
            @Parameter(name = "taskCode", description = "任务ID", required = true, example = "1"),
            @Parameter(name = "cron", description = "cron表达式", required = false, example = "0/5 * * * * ?")
    })
    public BaseResult startTask(@RequestParam String taskCode, @RequestParam String cron){
        return taskSchedulerTest.startCron(taskCode,cron);
    }

    @GetMapping("/stopById/{taskId}")
    @Operation(summary = "根据任务编码停止定时任务")
    @Parameters({
            @Parameter(name = "taskCode", description = "任务编码", required = true, example = "1")
    })
    public BaseResult stopTaskById(@PathVariable("taskCode") String taskCode){
        return taskSchedulerTest.stopCron(taskCode);
    }

    @GetMapping("/stopAll")
    @Operation(summary = "停止所有定时任务")
    public BaseResult stopAllTask(){
        return taskSchedulerTest.stopAllCron();
    }

    @GetMapping("/startAll")
    @Operation(summary = "开始所有定时任务")
    public BaseResult startAllTask(){
        return taskSchedulerTest.startAllCron();
    }

    @GetMapping("/showAll")
    @Operation(summary = "查看所有执行的定时任务")
    public BaseResult showAllTask(){
        return taskSchedulerTest.showAllTask();
    }


}
